package com.leetcode.LC;

import com.sun.jmx.remote.internal.ArrayQueue;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class LC1700 {
    public int countStudents(int[] students, int[] sandwiches) {
        //学生队列，三明治栈
        Queue<Integer> queue = new LinkedList<>();
        Stack<Integer> stack = new Stack<>();

        for (int student : students) {
            queue.add(student);
        }
        for (int i = sandwiches.length - 1; i >= 0; i--) {
            stack.push(sandwiches[i]);
        }

        while (!stack.isEmpty() && !queue.isEmpty()) {
            if (queue.contains(stack.peek())) {
                if (queue.peek()==stack.peek()){
                    queue.poll();
                    stack.pop();
                }else {
                    queue.add(queue.poll());
                }
            } else {
                return queue.size();
            }
        }
        return 0;
    }
}
